﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Delsjö
{
    public class Trip
    {
        public Trip()
        {
        }

        private List<Leg> legs = new List<Leg>();
        public List<Leg> Legs
        {
            get { return legs; }
            set { legs = value; }
        }

        public string Name
        {
            get
            {
                if (legs.Count == 0)
                    return String.Empty;
                string longName = "";
                for (int i = 0; i < legs.Count; i++)
                {
                    longName += legs[i].Name;
                    if (i == legs.Count - 1)
                        break;
                    longName += "->";
                }
                return longName;
            }
        }

        public string Time
        {
            get
            {
                if (legs.Count == 0)
                    return String.Empty;
                var startLeg = legs[0];
                var endLeg = legs[legs.Count - 1];
                if (string.IsNullOrEmpty(startLeg.OriginTimeStringRT) ||
                    string.IsNullOrEmpty(endLeg.OriginTimeStringRT))
                {
                    return startLeg.OriginTimeString + "->" + endLeg.DestinationTimeString;
                }
                return startLeg.OriginTimeStringRT + "->" + endLeg.DestinationTimeStringRT + " (" + startLeg.OriginTimeString + "->" + endLeg.DestinationTimeString + ")";
            }
        }

        public string Origins
        {
            get
            {
                if (legs.Count == 0)
                    return String.Empty;
                string longName = "";
                for (int i = 0; i < legs.Count; i++)
                {
                    longName += legs[i].Origin;
                    if (i == legs.Count - 1)
                        break;
                    longName += "->";
                }
                return longName;
            }
        }

    }

    public class Leg
    {
        private string from;
        public string Origin
        {
            get { return from; }
            set { from = value; }
        }

        private string to;
        public string Destination
        {
            get { return to; }
            set { to = value; }
        }

        private string originTimeString;
        public string OriginTimeString
        {
            get { return originTimeString; }
            set { originTimeString = value; }
        }

        private string originTimeStringRT;
        public string OriginTimeStringRT
        {
            get { return originTimeStringRT; }
            set { originTimeStringRT = value; }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string destinationTime;
        public string DestinationTimeString
        {
            get { return destinationTime; }
            set { destinationTime = value; }
        }

        private string destinationTimeStringRT;
        public string DestinationTimeStringRT
        {
            get { return destinationTimeStringRT; }
            set { destinationTimeStringRT = value; }
        }

        public DateTime DestinationTime { get; set; }
        public DateTime DestinationTimeRT { get; set; }

        public DateTime OriginTime { get; set; }
        public DateTime OriginTimeRT { get; set; }

        public string Type { get; set; }
    };

    public class RouteViewModel
    {
        public RouteViewModel()
        {
        }

        private List<Trip> trips = new List<Trip>();

        public List<Trip> Trips
        {
            get { return trips; }
            set { trips = value; }
        }
    };
}